package com.ztgf.pay.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.pay.models.vo.PayBankInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.pay.models.service.IPayBankInfoService;
import com.ztgf.pay.models.bo.PayBankInfoBO;
import com.ztgf.pay.models.dto.PayBankInfoDTO;

import java.util.List;

/**
 * 银行信息表控制器
 *
 * @author mxli
 * @Date 2020-08-20 16:48:00
 */

@RestController
@RequestMapping("/api/payBankInfo")
@Slf4j
@Api(value = "PayBankInfoApiController",tags = "银行信息表Api接口")
public class PayBankInfoApiController {

    @DubboReference
    private IPayBankInfoService payBankInfoService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<PayBankInfoDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        PayBankInfoDTO dto = payBankInfoService.selectById(id);

        return new Result<>(dto);
    }

    @PostMapping("/getByAddress")
    @ApiOperation(value = "根据开户行地址获取开户编号",notes = "根据开户行地址获取开户编号")
    @ApiImplicitParam(name = "bankAddress",value = "开户行地址",required = true,paramType = "query", dataType = "Long")
    public Result<PayBankInfoDTO> getByAddress(@RequestParam("bankAddress") String bankAddress){
        if(StrUtils.isEmpty(bankAddress)){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        PayBankInfoDTO dto = payBankInfoService.getByAddress(bankAddress);

        return new Result<>(dto);
    }

    @PostMapping("/getByNo")
    @ApiOperation(value = "根据开户行地址获取开户编号",notes = "根据开户行地址获取开户编号")
    @ApiImplicitParam(name = "bankNo",value = "开户行编号",required = true,paramType = "query", dataType = "String")
    public Result<PayBankInfoVO> getByNo(@RequestParam("bankNo") String bankNo){
        if(StrUtils.isEmpty(bankNo)){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        PayBankInfoVO vo = payBankInfoService.getByNo(bankNo);

        return new Result<>(vo);
    }

    @PostMapping("/queryList")
    @ApiOperation(value = "根据银行编号与区域获取开户行列表",notes = "根据银行编号与区域获取开户行列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankNo",value = "银行编号",required = true,paramType = "query", dataType = "String")
            ,@ApiImplicitParam(name = "areaCode",value = "区域编码",required = true,paramType = "query", dataType = "String")
    })
    public Result<List<PayBankInfoVO>> queryList(String bankNo, String areaCode){
        if(StrUtils.isEmpty(bankNo) || StrUtils.isEmpty(areaCode)){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        List<PayBankInfoVO> list = payBankInfoService.queryList(bankNo, areaCode);

        return new Result<>(list);
    }


    @ApiOperation(value = "银行信息表列表",notes = "银行信息表列表")
    @PostMapping("/queryPageList")
    public Result<Page<PayBankInfoDTO>> queryPageList(PayBankInfoBO bo){
        Wrapper<PayBankInfoDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<PayBankInfoDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = payBankInfoService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
